import request from '/@/utils/request'
import requestFile from '/@/utils/requestFile'
const serverContextPath = '/activiti/workflow'
export function workflowApi() {
	return {
		serverContextPath: serverContextPath,
		/**
		 * 流程设计数据列表，分页
		 * @param {*} params 
		 */
		queryModelList: (params: any) => {
			return request({
				url: serverContextPath + '/model/list',
				method: 'get',
				params: params
			})
		},

		/**
		 * 初始化一个模型
		 */
		modelAdd: () => {
			return request({
				url: serverContextPath + '/model/add',
				method: 'get'
			})
		},

		/**
		 * 根据id删除 流程
		 */
		deleteModel: (ids: any) => {
			return request({
				url: serverContextPath + `/model/deleteNone/` + ids,
				method: 'get',
			})
		},

		/**
		 * 根据ID删除流程设计数据
		 */
		modelDeleteById: (ids: any) => {
			return request({
				url: serverContextPath + '/model/delete/' + ids,
				method: 'get',
			})
		},

		/**
		 * 发布流程
		 */
		modelDeploy: (ids: any) => {
			return request({
				url: serverContextPath + '/model/deploy/' + ids,
				method: 'post'
			})
		},

		/**
		 * 下载流程文件
		 * @param {*} id 
		 */
		exportXml: (deploymentId: string) => {
			var a = document.createElement('a')
			a.href = import.meta.env.VITE_API_URL + serverContextPath + '/model/export/' + deploymentId
			a.click()
		},

		/**
		 * 根据部署id获取流程定义
		 * @param {} deploymentId 
		 */
		getProcessDefinition: (deploymentId: string) => {
			return request({
				url: serverContextPath + '/model/getProcessDefinition/' + deploymentId,
				method: 'get',
			})
		},

		/**
		 * 流程版本数据列表
		 *
		 */
		getProcessList: (params: any) => {
			return request({
				url: serverContextPath + '/model/getProcessDefinitionHis',
				method: 'get',
				params: params
			})
		},

		/**
		 * 上传流程文件
		 * @param {*} formData 
		 */
		uploadModelFile: (formData: any) => {
			return requestFile({
				url: serverContextPath + '/model/uploadModelFile',
				method: 'post',
				data: formData
			})
		},

		/**
		 * 获取策略列表
		 */
		queryStrategyList: (params: any) => {
			return request({
				url: serverContextPath + '/strategy/list',
				method: 'post',
				data: params
			})
		},
		/**
		 * 根据id删除策略配置
		 */
		strategyDeleteById: (ids: any) => {
			return request({
				url: serverContextPath + '/strategy/delete',
				method: 'post',
				data: ids
			})
		},
		/**
		 * 根据id获取策略配置信息
		 */
		queryStrategyInfo: (ids: any) => {
			return request({
				url: serverContextPath + `/strategy/info/${ids}`,
				method: 'get',
			})
		},
		/**
		 * 添加策略配置
		 */
		strategySave: (datas: any) => {
			return request({
				url: serverContextPath + `/strategy/save`,
				method: 'post',
				data: datas
			})
		},

		/**
		 * (修改)页面目录策略配置
		 */
		strategyUpdate: (datas: any) => {
			return request({
				url: serverContextPath + `/strategy/update`,
				method: 'post',
				data: datas
			})
		},

		/**
		 * 根据流程编码获取第一个节信息
		 * @param {} processKey 
		 */
		getDefFirstNode: (processKey: string) => {
			return request({
				url: serverContextPath + `/model/getDefFirstNode/${processKey}`,
				method: 'get',
			})
		},

		/**
		 * 获取开始节点信息
		 * @param {*} processKey 
		 */
		getModelStartNodeInfo: (processKey: string) => {
			return request({
				url: serverContextPath + `/model/getModelStartNodeInfo/${processKey}`,
				method: 'get',
			})
		},

		/**
		 * 提交流程任务
		 * @param {*} data 
		 */
		subminTask: (data: any) => {
			return request({
				url: serverContextPath + `/task/subminTask`,
				method: 'post',
				data: data
			})
		},

		/**
		 * 待办任务列表
		 * @param {*} datas 
		 */
		queryTodoTaskList: (datas: any) => {
			return request({
				url: serverContextPath + '/task/todoList',
				method: 'get',
				params: datas
			})
		},

		/**
		 * 授权任务列表
		 */
		queryAuthorizationTaskList: (params: any) => {
			return request({
				url: serverContextPath + '/task/authorizationTaskList',
				method: 'get',
				params: params
			})
		},

		/**
		 * 根据任务id查询详情界面（动态表单时）信息
		 * @param {*} taskId 
		 */
		getTaskNodeInfo: (taskId: string) => {
			return request({
				url: serverContextPath + `/task/getTaskNodeInfo/${taskId}`,
				method: 'get',
			})
		},

		/**
		 * 根据流程实例id查询审批记录
		 * @param {*} processId 
		 */
		getHisTaskByProcessId: (processId: string) => {
			return request({
				url: serverContextPath + '/task/getHisTaskByProcessId/' + processId,
				method: 'get',
			})
		},

		/**
		 * 根据业务主键查询审批记录
		 */
		getHisTaskByBusNo: (busNo: string) => {
			return request({
				url: serverContextPath + '/task/getHisTaskByBusNo',
				method: 'get',
				params: {
					'busNo': busNo
				}
			})
		},

		/**
		 * 获取可退回节点
		 */
		getRetractNode: (params: any) => {
			return request({
				url: serverContextPath + '/task/getRetractNode',
				method: 'get',
				params: params
			})
		},
		/**
		 * 获取可退回节点
		 */
		getRetractNodeByTaskId: (taskId: string) => {
			return request({
				url: serverContextPath + `/task/getRetractNodeByTaskId/${taskId}`,
				method: 'get'
			})
		},
		/**
		 * 根据任务编号获取审批意见
		 * @param taskId
		 * @returns {*}
		 */
		getApproveAdviceByTaskId: (taskId: string) => {
			return request({
				url: serverContextPath + `/task/getApproveAdviceByTaskId/${taskId}`,
				method: 'get',
			})
		},

		/**
		 * 查询流程名称列表
		 */

		queryProcessNames: () => {
			return request({
				url: serverContextPath + `/model/processDefNames`,
				method: 'get',
			})
		},

		/**
		 * 参与的流程列表
		 */
		queryParticipationProcessList: (params: any) => {
			return request({
				url: serverContextPath + '/task/queryParticipationProcessList',
				method: 'get',
				params: params
			})
		},

		/**
		 * 发起流程列表
		 */
		queryCreateProcessList: (params: any) => {
			return request({
				url: serverContextPath + '/task/createProcessList',
				method: 'get',
				params: params
			})
		},

		/**
		 * 根据流程实例获取最后一个执行节点的表单信息（用于展现动态表单的详情页面）
		 * @param {*} processId 
		 */
		getProcessInsLastNodeInfo: (processId: string) => {
			return request({
				url: serverContextPath + `/task/getProcessInsLastNodeInfo/${processId}`,
				method: 'get',
			})
		},

		/**
		 * 根据流程实例id获取当前用户处理（不包含撤回、终止）过的节点
		 * @param processid 流程实例id
		 * @returns {*}
		 */
		getCanRecallNode: (processid: string) => {
			return request({
				url: serverContextPath + `/task/getCanRecallNode/${processid}`,
				method: 'get',
			})
		},

		/**
		 * 参与人撤回流程
		 * @param params
		 'processid': 流程实例id,
		'recallNodeKey': 要撤回的节点key,
		'deleteReason': 撤回原因
		}
		* @returns {*}
		*/
		recallMaster: (params: any) => {
			return request({
				url: serverContextPath + `/task/recallMaster`,
				method: 'get',
				params: params
			})
		},

		/**
		 * 发起人撤回流程
		 */
		taskRestart: (ids: any) => {
			return request({
				url: serverContextPath + '/task/restart',
				method: 'get',
				params: {
					'processid': ids
				}
			})
		},

		/**
		 *
		 * 流程列表查询
		 */
		querygetProcessList: (params: any) => {
			return request({
				url: serverContextPath + '/task/allProcessList',
				method: 'get',
				params: params
			})
		},

		/**
		 * 终止流程
		 */
		deleteProcess: (params: any) => {
			return request({
				url: serverContextPath + '/task/deleteProcess',
				method: 'get',
				params: params
			})
		},

		/**
		 * 转授权数据列表
		 */
		queryDelegationList: (params: any) => {
			return request({
				url: serverContextPath + '/delegation/list',
				method: 'get',
				params: params
			})
		},

		/**
		 * 根据ID删除转授权数据
		 */
		delegationDeleteById: (ids: any) => {
			return request({
				url: serverContextPath + '/delegation/delete',
				method: 'post',
				data: ids
			})
		},
		/**
		 * 根据id获取授权信息
		 */
		queryDelegationInfoById: (ids: any) => {
			return request({
				url: serverContextPath + `/delegation/info/${ids}`,
				method: 'get',
			})
		},
		/**
		 * (添加)保存授权信息
		 */
		AddDelegation: (params: any) => {
			return request({
				url: serverContextPath + `/delegation/addDelegation`,
				method: 'post',
				data: params
			})
		},
		/**
		 * (修改)保存授权信息
		 */
		updateDelegation: (params: any) => {
			return request({
				url: serverContextPath + `/delegation/updateDelegation`,
				method: 'post',
				data: params
			})
		},

		submitretract: (params: any) => {
			return request({
				url: serverContextPath + '/task/rejectTaskToOld',
				method: 'get',
				params: params
			})
		},
		/**
		 * 指派处理人，增加而非替换
		 * @param ids
		 */
		addAssignee: (checkProcessId: string, ids: any) => {
			return request({
				url: serverContextPath + '/task/addAssignee',
				method: 'post',
				data: {
					'checkProcessId': checkProcessId,
					'ids': ids
				}
			})
		},
		/**
		 * 暂存审批意见
		 * @param taskId 任务id
		 * @param approveAdvice 审批意见
		 * @returns {*}
		 */
		saveApproveAdvice: (taskId: string, approveAdvice: string, authCatagory: string, owner: string) => {
			return request({
				url: serverContextPath + `/activiti/task/saveApproveAdvice`,
				method: 'post',
				data: {
					'taskId': taskId,
					'approveAdvice': approveAdvice,
					'authCatagory': authCatagory,
					'owner': owner
				}
			})
		}
	}
}